package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.AdminPageDaoMarketValueAccountVO;
import com.sc.nft.entity.vo.DaoFilterUserVO;
import com.sc.nft.entity.vo.FilterListVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.FilterIncomeList;
import com.sc.nft.mapper.FilterIncomeListMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

/**
 * (sc_filter_income_list)数据DAO
 *
 * @author Sun
 * @since 2022-10-18 11:00:01
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class FilterIncomeListDao extends ServiceImpl<FilterIncomeListMapper, FilterIncomeList> {

    public FilterIncomeList getIsTeamIncomeByUserId(Long userId) {
        LambdaQueryWrapper<FilterIncomeList> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FilterIncomeList::getUserId,userId);
        return getOne(wrapper);
    }

    public FilterIncomeList getIsTeamIncomeByUserIdAndDaoId(Long daoId,Long userId) {
        LambdaQueryWrapper<FilterIncomeList> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FilterIncomeList::getDaoId,daoId);
        wrapper.eq(FilterIncomeList::getUserId,userId);
        return getOne(wrapper);
    }

    public boolean checkIsFilterAccount(Long daoId,Long userId) {
        LambdaQueryWrapper<FilterIncomeList> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FilterIncomeList::getDaoId,daoId);
        wrapper.eq(FilterIncomeList::getUserId,userId);
        return count(wrapper)==1;
    }

    public boolean checkListIsFilterAccount(List<Long> daoIds,Long userId) {
        LambdaQueryWrapper<FilterIncomeList> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(FilterIncomeList::getDaoId,daoIds);
        wrapper.eq(FilterIncomeList::getUserId,userId);
        return count(wrapper)==1;
    }


    public Page<FilterListVO> getPageFilterList(Long daoId,Integer pageNo, Integer pageSize,String userTel) {
        return baseMapper.getPageFilterList(new Page<>(pageNo,pageSize),daoId,userTel);
    }
    public Page<DaoFilterUserVO> getDaoFilterUser(Long daoId,   String userTel,Page page) {
        return baseMapper.getDaoFilterUser(page,daoId,userTel);
    }
    public Boolean updateIsDeleteById(Long id) {
        UpdateWrapper<FilterIncomeList> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",id);
        wrapper.set("is_delete",Boolean.TRUE);
        return update(wrapper);
    }


    public List<Long> getMarketAccountIds() {
        List<FilterIncomeList> list = list();
        return list.stream().map(FilterIncomeList::getUserId).collect(Collectors.toList());
    }

    public List<FilterIncomeList> getByDaoId(Long daoId) {
        return lambdaQuery().eq(FilterIncomeList::getDaoId,daoId).list();
    }

    public Boolean getIsContainsUserId(Long userId) {
        LambdaQueryWrapper<FilterIncomeList> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FilterIncomeList::getUserId,userId);
        Integer count = count(wrapper);
        if(count > 0 ){
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }

    public FilterIncomeList getByUserId(Long userId) {
        LambdaQueryWrapper<FilterIncomeList> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FilterIncomeList::getUserId,userId);
        return getOne(wrapper);
    }

    public Page<AdminPageDaoMarketValueAccountVO> getPage(Long daoId,String userTel, Integer pageNo, Integer pageSize) {
        return baseMapper.getPage(new Page<>(pageNo,pageSize),daoId,userTel);
    }

    public List<Long> getListByDaoId(Long daoId) {
        return baseMapper.getListByDaoId(daoId);
    }
}